home *** CD-ROM | disk | FTP | other *** search
/ Ultimedia 1 / Ultimedia 1.iso / tools / animplayer / amipeg / source.lha / sjrevdct.s < prev    next >
Encoding:
Text File  |  1994-03-03  |  12.9 KB  |  778 lines

  1. ;
  2. ; This code implements the basic idct on a 8x8 pixel block.
  3. ; Basically, it's the same as in the JPEG engine, with the sole difference
  4. ; that it's inlined and register-wise a little bit more optimized there.
  5. ;
  6. ; This is a complete rewrite in assembler. Heavy stuff. Lotsa work.
  7. ;
  8. ; Michael Rausch  13-2-94  13:53:00
  9. ;
  10.  
  11. ;
  12. ; The whole code handles D-Frames not very well, but I'll fix it on day.
  13. ;
  14.  
  15.  
  16.     SECTION    text,CODE
  17.  
  18. DCTSIZE    EQU    8
  19.  
  20. PASS1_BITS EQU    2
  21. CONST_BITS EQU    13
  22.  
  23.  
  24. FIX_0_298631336 EQU    2446    ;1    +    $98e    100110001110
  25. _FIX_0_390180644 EQU    -3196    ;2    -    $c7c
  26. FIX_0_541196100 EQU    4433    ;3    +    $1151    u
  27. FIX_0_765366865 EQU    6270    ;4    +    $187e    u
  28. _FIX_0_899976223 EQU    -7373    ;5    -    $1ccd
  29. FIX_1_175875602 EQU    9633    ;6    +    $25a1
  30. FIX_1_501321110 EQU    12299    ;7    +    $300b
  31. _FIX_1_847759065 EQU    -15137    ;8    -    $3b21    u
  32. _FIX_1_961570560 EQU    -16069    ;9    -    $3ec5
  33. FIX_2_053119869 EQU    16819    ;10    +    $41b3
  34. _FIX_2_562915447 EQU    -20995    ;11    -    $5203
  35. FIX_3_072711026 EQU    25172    ;12    +    $6254
  36.  
  37. ; FIX_1_847759065-FIX_0_765366865 = 2* FIX_0_541196100
  38.  
  39.     ifeq    1
  40. ; **************************************************************************
  41.  
  42. ; Pre compute singleton coefficient IDCT values.
  43. ;
  44. ; void init_pre_idct(void)
  45.  
  46. ;    XDEF @init_pre_idct
  47. @init_pre_idct:
  48.     movem.l    d2/a2,-(sp)
  49.  
  50.     lea    PreIDCT,a2
  51.     move.w    #64*64/4/4-1,d2
  52. preidctclr:
  53.     clr.l    (a2)+
  54.     clr.l    (a2)+
  55.     clr.l    (a2)+
  56.     clr.l    (a2)+
  57.     dbra    d2,preidctclr
  58.  
  59.     lea    PreIDCT+63*64*2,a2
  60.     moveq    #63,d2
  61. preidctloop:
  62.     move.w    #2048,(a2,d2.w)
  63.     move.l    a2,a0
  64.     bsr    @j_rev_dct
  65.     sub.w    #64,a2
  66.     dbra    d2,preidctloop
  67.  
  68.     movem.l    (sp)+,d2/a2
  69.     rts
  70.     endc
  71.  
  72. ; **************************************************************************
  73.  
  74.     XDEF    @j_rev_dct
  75. @j_rev_dct:
  76.  
  77. JREVDCTREGS REG    d0-d7/a5
  78.  
  79.     movem.l    JREVDCTREGS,-(sp)
  80.  
  81.     sub.w    #16,sp
  82.  
  83.     move.l    a0,-(sp)
  84.     lea    compose1(pc),a5
  85.     moveq    #DCTSIZE-1,d7
  86. idct1:    move.l    d7,-(sp)
  87.  
  88.     lea    2(a0),a1
  89.     move.l    (a1)+,d2
  90.     move.l    d2,d0
  91.     move.l    (a1)+,d4
  92.     move.l    (a1)+,d3
  93.     or.l    d4,d0
  94.     or.w    (a1)+,d0
  95.     or.l    d3,d0
  96.     bne.s    idct1_no_ac0
  97.     move.w    (a0),d0
  98.     lsl.w    #PASS1_BITS,d0
  99.     move.w    d0,d1
  100.     swap    d0
  101.     move.w    d1,d0
  102.     REPT    4
  103.     move.l    d0,(a0)+
  104.     ENDR
  105.     bra    idct1_next
  106. idct1_no_ac0:
  107.  
  108.     move.w    d2,d1            ; 2
  109.     add.w    d3,d1            ; 6
  110.     muls    #FIX_0_541196100,d1
  111.     muls    #_FIX_1_847759065,d3
  112.     add.l    d1,d3
  113.     muls    #FIX_0_765366865,d2
  114.     add.l    d1,d2
  115.  
  116.     move.w    (a0),d0
  117.     ext.l    d0            ; 0
  118.     ext.l    d4            ; 4
  119.     move.l    d0,d5
  120.     sub.l    d4,d5
  121.     add.l    d0,d4
  122.  
  123.     lsl.l    #5,d4
  124.     lsl.l    #5,d5
  125.     addq.l    #1<<2,d4
  126.     addq.l    #1<<2,d5
  127.     lsl.l    #8,d4
  128.     lsl.l    #8,d5
  129.  
  130.     lea    12(sp),a1    ; top + 2 longs -> 16 bytes platz auf dem stack
  131.     move.l    d4,d0
  132.     add.l    d2,d4
  133.     move.l    d4,(a1)+    ; tmp10
  134.     sub.l    d2,d0
  135.     move.l    d5,d1
  136.     add.l    d3,d5
  137.     move.l    d5,(a1)+    ; tmp11
  138.     sub.l    d3,d1
  139.     move.l    d1,(a1)+    ; tmp12
  140.     move.l    d0,(a1)+    ; tmp13
  141.  
  142. odd_part1: 
  143.     move.w    7*2(a0),d1    ;7
  144.     beq    o0xxx
  145. o1xxx:    move.w    5*2(a0),d2    ;5
  146.     beq    o10xx
  147. o11xx:    move.w    3*2(a0),d3    ;3
  148.     beq    o110x
  149. o111x:    move.w    1*2(a0),d4    ;1
  150.     bne.s    odd1_1111
  151.  
  152.  
  153. ;    7531
  154. odd1_1110:
  155.     move.w    d2,d6
  156.     move.w    d1,d0
  157.     moveq    #0,d4
  158.     bra.s    abk_2
  159.  
  160. ;    7531
  161. odd1_1111:
  162.     move.w    d2,d6
  163.     add.w    d4,d6
  164.     move.w    d1,d0
  165.     add.w    d4,d0
  166.     muls    #FIX_1_501321110,d4
  167. abk_2:    move.w    d1,d5
  168.     add.w    d3,d5
  169.     move.w    d5,d7
  170.     add.w    d6,d7
  171.     muls    #FIX_1_175875602,d7
  172.     muls    #_FIX_1_961570560,d5
  173.     muls    #_FIX_0_390180644,d6
  174.      add.l    d7,d5
  175.     add.l    d7,d6
  176.     move.w    d2,d7
  177.     add.w    d3,d7
  178.     muls    #FIX_0_298631336,d1
  179.     muls    #FIX_2_053119869,d2
  180.     muls    #FIX_3_072711026,d3
  181.     muls    #_FIX_0_899976223,d0
  182.     muls    #_FIX_2_562915447,d7
  183.     add.l    d0,d1
  184.     add.l    d7,d2
  185.     add.l    d5,d1
  186.     add.l    d6,d2
  187.     add.l    d3,d5
  188.     add.l    d4,d6
  189.     add.l    d7,d5
  190.     add.l    d0,d6
  191.     jmp    (a5)
  192.  
  193. o2110x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  194.     bne.s    odd1_1101
  195.  
  196. ;    7531
  197. odd1_1100:
  198.     move.w    d2,d6
  199.     move.w    d1,d3
  200.     moveq    #0,d4
  201.     bra.s    abk_3
  202.  
  203. o110x:    move.w    1*2(a0),d4    ;1
  204.     beq.s    odd1_1100
  205.  
  206. ;    7531
  207. odd1_1101:
  208.     move.w    d2,d6
  209.     move.w    d1,d3
  210.     add.w    d4,d6
  211.     add.w    d4,d3
  212.     muls    #FIX_1_501321110,d4
  213. abk_3:
  214.     move.w    d1,d5
  215.     move.w    d5,d7
  216.     add.w    d6,d7
  217.     muls    #FIX_1_175875602,d7    
  218.     muls    #_FIX_1_961570560,d5
  219.     muls    #_FIX_0_390180644,d6
  220.      add.l    d7,d5
  221.     add.l    d7,d6
  222.     move.w    d2,d0
  223.     muls    #FIX_0_298631336,d1
  224.     muls    #FIX_2_053119869,d2
  225.     muls    #_FIX_0_899976223,d3
  226.     muls    #_FIX_2_562915447,d0
  227.     add.l    d3,d1
  228.     add.l    d0,d2
  229.     add.l    d5,d1
  230.     add.l    d6,d2
  231.     add.l    d4,d6
  232.     add.l    d0,d5
  233.     add.l    d3,d6
  234.     jmp    (a5)
  235.  
  236. o10xx:    move.w    3*2(a0),d3    ;3
  237.     beq    o100x
  238. o101x:    move.w    1*2(a0),d4    ;1
  239.     beq.s    odd1_1010
  240.  
  241. ;    7531
  242. odd1_1011:
  243.     move.w    d1,d5
  244.     add.w    d3,d5
  245.     move.w    d1,d0
  246.     move.w    d4,d6
  247.     add.w    d4,d0
  248.     muls    #FIX_1_501321110,d4
  249.     move.w    d5,d7
  250.     add.w    d6,d7
  251.     muls    #_FIX_0_390180644,d6
  252. abk_4:    muls    #FIX_1_175875602,d7
  253.     muls    #_FIX_1_961570560,d5
  254.     add.l    d7,d6
  255.      add.l    d7,d5
  256.     move.w    d3,d7
  257.     muls    #FIX_0_298631336,d1
  258.     muls    #FIX_3_072711026,d3
  259.     muls    #_FIX_0_899976223,d0
  260.     muls    #_FIX_2_562915447,d7
  261.     add.l    d0,d1
  262.     move.l    d6,d2
  263.     add.l    d5,d1
  264.     add.l    d7,d2
  265.     add.l    d3,d5
  266.     add.l    d4,d6
  267.     add.l    d7,d5
  268.     add.l    d0,d6
  269.     jmp    (a5)
  270.  
  271. o210xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  272.     beq    o2100x
  273. o2101x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  274.     bne.s    odd1_1011
  275.  
  276. ;    7531
  277. odd1_1010:
  278.     move.w    d1,d5
  279.     add.w    d3,d5
  280.     move.w    d1,d0
  281.     moveq    #0,d4
  282.     move.w    d5,d7
  283.     moveq    #0,d6
  284.     bra.s    abk_4
  285.  
  286. o100x:    move.w    1*2(a0),d4    ;1
  287.     beq.s    odd1_1000
  288.  
  289. ;    7531
  290. odd1_1001:
  291.     move.w    d1,d0
  292.     add.w    d4,d0
  293.     move.w    d1,d5
  294.     move.w    d4,d6
  295.     move.w    d0,d7
  296.     muls    #FIX_1_175875602,d7
  297.     muls    #_FIX_1_961570560,d5
  298.     muls    #_FIX_0_390180644,d6
  299.      add.l    d7,d5
  300.     add.l    d7,d6
  301.     muls    #FIX_0_298631336,d1
  302.     muls    #FIX_1_501321110,d4
  303.     muls    #_FIX_0_899976223,d0
  304.     add.l    d0,d1
  305.     add.l    d5,d1
  306.     move.l    d6,d2
  307.     add.l    d4,d6
  308.     add.l    d0,d6
  309.     jmp    (a5)
  310.  
  311. o2100x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  312.     bne.s    odd1_1001
  313.  
  314. ;    7531
  315. odd1_1000:
  316.     move.w    d1,d2
  317.     move.w    d1,d3
  318.     move.w    d1,d5
  319.     move.w    d1,d6
  320.     muls    #FIX_1_175875602,d2
  321.     muls    #FIX_1_175875602+_FIX_0_899976223,d6
  322.     muls    #FIX_1_175875602+_FIX_1_961570560,d5
  323.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_1_961570560+FIX_0_298631336,d1
  324.     jmp    (a5)
  325.  
  326.  
  327. o0xxx:    move.w    5*2(a0),d2    ;5
  328.     beq    o00xx
  329. o01xx:    move.w    3*2(a0),d3    ;3
  330.     beq    o010x
  331. o011x:    move.w    1*2(a0),d4    ;1
  332.     beq.s    odd1_0110
  333.  
  334. ;    7531
  335. odd1_0111:    ; opt8
  336.     move.w    d2,d6
  337.     add.w    d4,d6
  338.     move.w    d4,d1
  339.     muls    #FIX_1_501321110,d4
  340.     muls    #_FIX_0_899976223,d1
  341. abk_1:    move.w    d2,d0
  342.     add.w    d3,d0
  343.     move.w    d3,d5
  344.  
  345.     move.w    d5,d7
  346.     add.w    d6,d7
  347.     muls    #FIX_1_175875602,d7
  348.     muls    #_FIX_1_961570560,d5
  349.     muls    #_FIX_0_390180644,d6                ; ???? 2
  350.      add.l    d7,d5
  351.     add.l    d7,d6
  352.  
  353.     muls    #FIX_2_053119869,d2
  354.     muls    #FIX_3_072711026,d3
  355.     muls    #_FIX_2_562915447,d0
  356.     add.l    d0,d2
  357.     add.l    d6,d2
  358.     add.l    d4,d6
  359.     add.l    d1,d6
  360.     add.l    d5,d1
  361.     add.l    d3,d5
  362.     add.l    d0,d5
  363.     jmp    (a5)
  364.  
  365. o20xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  366.     beq    o200xx
  367. o201xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  368.     beq.s    o2010x
  369. o2011x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  370.     bne.s    odd1_0111
  371.  
  372. ;    7531
  373. odd1_0110:
  374.     move.w    d2,d6
  375.     moveq.l    #0,d1
  376.     moveq.l    #0,d4
  377.     bra.s    abk_1
  378.  
  379. o010x:    move.w    1*2(a0),d4    ;1
  380.     beq.s    odd1_0100
  381.  
  382. ;    7531
  383. odd1_0101:
  384.     move.w    d2,d6
  385.     move.w    d2,d7
  386.     add.w    d4,d6
  387.     move.w    d4,d1
  388.     move.w    d6,d5
  389.     muls    #FIX_1_175875602,d5
  390.     muls    #_FIX_0_390180644+FIX_1_175875602,d6
  391.     muls    #FIX_2_053119869+_FIX_2_562915447,d2
  392.     muls    #FIX_1_501321110,d4
  393.     muls    #_FIX_0_899976223,d1
  394.     muls    #_FIX_2_562915447,d7
  395.     add.l    d6,d2
  396.     add.l    d1,d6
  397.     add.l    d5,d1
  398.     add.l    d7,d5
  399.     add.l    d4,d6
  400.     jmp    (a5)
  401.  
  402. o2010x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  403.     bne.s    odd1_0101
  404.  
  405. ;    7531
  406. odd1_0100:
  407.     move.w    d2,d6
  408.     move.w    d2,d1
  409.     move.w    d2,d4
  410.     move.w    d2,d5
  411.     muls    #FIX_1_175875602,d1
  412.     muls    #FIX_1_175875602+_FIX_2_562915447,d5
  413.     muls    #FIX_1_175875602+_FIX_0_390180644,d6
  414.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_0_390180644+FIX_2_053119869,d2
  415.     jmp    (a5)
  416.  
  417. o00xx:    move.w    3*2(a0),d3    ;3
  418.     beq.s    o000x
  419. o001x:    move.w    1*2(a0),d4    ;1
  420.     beq.s    odd1_0010
  421.  
  422. ;    7531
  423. odd1_0011:    ; opt12
  424.     move.w    d3,d2
  425.     move.w    d3,d5
  426.     move.w    d4,d1
  427.     move.w    d4,d6
  428.     move.w    d3,d7
  429.     add.w    d4,d7
  430.     muls    #FIX_1_175875602,d7
  431.     muls    #_FIX_1_961570560,d5
  432.     muls    #_FIX_0_390180644,d6
  433.      add.l    d7,d5
  434.     add.l    d7,d6
  435.     muls    #_FIX_2_562915447+FIX_3_072711026,d3
  436.     muls    #_FIX_0_899976223+FIX_1_501321110,d4
  437.     muls    #_FIX_0_899976223,d1
  438.     muls    #_FIX_2_562915447,d2
  439.     add.l    d5,d1
  440.     add.l    d6,d2
  441.     add.l    d3,d5
  442.     add.l    d4,d6
  443.     jmp    (a5)
  444.  
  445. o200xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  446.     beq    o2000x
  447. o2001x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  448.     bne.s    odd1_0011
  449.  
  450. ;    7531
  451. odd1_0010:
  452.     move.w    d3,d2
  453.     move.w    d3,d5
  454.     move.w    d3,d1
  455.     move.w    d3,d6
  456.     muls    #FIX_1_175875602,d6
  457.     muls    #FIX_1_175875602+_FIX_2_562915447,d2
  458.     muls    #FIX_1_175875602+_FIX_1_961570560,d1
  459.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_1_961570560+FIX_3_072711026,d5
  460.     jmp    (a5)
  461.  
  462. o000x:    move.w    1*2(a0),d4    ;1
  463.     beq.s    odd1_0000
  464.  
  465. ;    7531
  466. odd1_0001:    ; opt 14
  467.  
  468.     move.w    d4,d1
  469.     move.w    d4,d2
  470.     move.w    d4,d5
  471.     move.w    d4,d6
  472.     muls    #FIX_1_175875602,d5
  473.     muls    #FIX_1_175875602+_FIX_0_899976223,d1
  474.     muls    #FIX_1_175875602+_FIX_0_390180644,d2
  475.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_0_390180644+FIX_1_501321110,d6
  476.     jmp    (a5)
  477.  
  478. ; priority: 14 12 8 0 
  479.  
  480. ;    7531
  481. odd1_0000:
  482.     moveq    #CONST_BITS-PASS1_BITS,d7    ; optimized compose !
  483.  
  484.     lea    12(sp),a1
  485.     move.l    (a1)+,d0    ; tmp10
  486.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d0
  487.     move.l    (a1)+,d1    ; tmp11
  488.     lsr.l    d7,d1
  489.     move.w    d1,d0
  490.  
  491.     move.l    (a1)+,d2    ; tmp12
  492.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  493.     move.l    (a1)+,d3    ; tmp13
  494.     lsr.l    d7,d3
  495.     move.w    d3,d2
  496.  
  497.     move.l    d0,(a0)+
  498.     move.l    d2,(a0)+
  499.     swap    d2
  500.     swap    d0
  501.     move.l    d2,(a0)+
  502.     move.l    d0,(a0)+
  503.  
  504.     bra.s    idct1_next
  505.  
  506. ; keep 1 2 5 6
  507.  
  508. compose1: moveq    #CONST_BITS-PASS1_BITS,d7
  509.  
  510.     lea    12(sp),a1
  511.     move.l    (a1)+,d4    ; tmp10
  512.     sub.l    d6,d4
  513.     add.l    d6,d6
  514.     add.l    d4,d6
  515.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d6
  516.     move.l    (a1)+,d3    ; tmp11
  517.     sub.l    d5,d3
  518.     add.l    d5,d5
  519.     add.l    d3,d5
  520.     lsr.l    d7,d5
  521.     move.w    d5,d6
  522.     move.l    d6,(a0)+
  523.     move.l    (a1)+,d6    ; tmp12
  524.     sub.l    d2,d6
  525.     add.l    d2,d2
  526.     add.l    d6,d2
  527.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  528.     move.l    (a1)+,d5    ; tmp13
  529.     sub.l    d1,d5
  530.     add.l    d1,d1
  531.     add.l    d5,d1
  532.     lsr.l    d7,d1
  533.     move.w    d1,d2
  534.     move.l    d2,(a0)+
  535.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d5
  536.     lsr.l    d7,d6
  537.     move.w    d6,d5
  538.     move.l    d5,(A0)+
  539.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d3
  540.     lsr.l    d7,d4
  541.     move.w    d4,d3
  542.     move.l    d3,(a0)+
  543.  
  544. idct1_next:
  545.     move.l    (sp)+,d7
  546.     dbra    d7,idct1
  547.  
  548. ; *******************************************************
  549.  
  550.     move.l    (sp)+,a0
  551.     lea    compose2(pc),a5
  552.     moveq    #DCTSIZE-1,d7
  553. idct2:    move.l    d7,-(sp)
  554.  
  555.  
  556. odd_part2: 
  557.     move.w    7*DCTSIZE*2(a0),d1    ;7
  558.     beq    o20xxx
  559. o21xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  560.     beq    o210xx
  561. o211xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  562.     beq    o2110x
  563. o2111x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  564.     beq    odd1_1110
  565.     bra    odd1_1111
  566.  
  567. o2000x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  568.     bne    odd1_0001
  569.  
  570. odd0_0000:
  571.     move.w    2*DCTSIZE*2(a0),d2
  572.     move.w    4*DCTSIZE*2(a0),d4
  573.     move.w    6*DCTSIZE*2(a0),d3
  574.     move.w    d2,d0
  575.     add.w    d3,d0
  576.     muls    #FIX_0_541196100/4,d0
  577.     muls    #_FIX_1_847759065/4,d3
  578.     add.l    d0,d3
  579.     muls    #FIX_0_765366865/4,d2
  580.     add.l    d0,d2
  581.  
  582.     move.w    (a0),d0
  583.     add.w    #1<<(PASS1_BITS+3-1),d0        ; precalc from the descaling part below
  584.     ext.l    d4
  585.     ext.l    d0
  586.     move.l    d0,d5
  587.     sub.l    d4,d5
  588.     add.l    d0,d4
  589.  
  590.     moveq    #CONST_BITS-2,d0
  591.     lsl.l    d0,d4
  592.     lsl.l    d0,d5
  593.  
  594.     move.l    d4,d0
  595.     add.l    d2,d4
  596.     swap     d4
  597.     move.w    d4,(a0)+
  598.     sub.l    d2,d0
  599.     move.w    d4,7*DCTSIZE*2-2(a0)
  600.     swap    d0
  601.     move.w    d0,3*DCTSIZE*2-2(a0)
  602.     move.l    d5,d4
  603.     move.w    d0,4*DCTSIZE*2-2(a0)
  604.     add.l    d3,d5
  605.     swap     d5
  606.     move.w    d5,1*DCTSIZE*2-2(a0)
  607.     sub.l    d3,d4
  608.     move.w    d5,6*DCTSIZE*2-2(a0)
  609.     swap    d4
  610.     move.w    d4,2*DCTSIZE*2-2(a0)
  611.     move.w    d4,5*DCTSIZE*2-2(a0)
  612.     bra    idct2_next
  613.  
  614. compose2:
  615.     move.w    2*DCTSIZE*2(a0),d3
  616.     move.w    4*DCTSIZE*2(a0),d4
  617.     move.w    6*DCTSIZE*2(a0),d7
  618.  
  619.     move.w    d3,d0
  620.     add.w    d7,d0
  621.     muls    #FIX_0_541196100,d0
  622.     muls    #_FIX_1_847759065,d7
  623.     add.l    d0,d7
  624.     muls    #FIX_0_765366865,d3
  625.     add.l    d0,d3
  626.  
  627.     asr.l    #2,d7
  628.     asr.l    #2,d3
  629.     move.l    d7,a3
  630.  
  631.     move.w    (a0),d0
  632.     add.w    #1<<(PASS1_BITS+3-1),d0    ; precalc from the descaling part below
  633.     ext.l    d4
  634.     ext.l    d0
  635.     move.l    d0,d7
  636.     sub.l    d4,d7
  637.     add.l    d0,d4
  638.  
  639.     moveq    #CONST_BITS-2,d0
  640.     lsl.l    d0,d4
  641.     lsl.l    d0,d7
  642.  
  643.  
  644.     asr.l    #2,d6
  645.     asr.l    #2,d5
  646.     asr.l    #2,d2
  647.     asr.l    #2,d1
  648.  
  649.  
  650.     move.l    d4,d0
  651.     add.l    d3,d4
  652.     sub.l    d3,d0
  653.  
  654.     move.l    d7,d3
  655.     add.l    a3,d7
  656.     sub.l    a3,d3
  657.  
  658.  
  659.     sub.l    d6,d4
  660.     add.l    d6,d6
  661.     add.l    d4,d6
  662.  
  663.     swap    d6                ; moveq    #CONST_BITS+PASS1_BITS+3  -2   ,d6   ;   asr.l d6,d3
  664.     move.w    d6,(a0)+
  665.     swap    d4
  666.     move.w    d4,7*DCTSIZE*2-2(a0)
  667.  
  668.     sub.l    d1,d0
  669.     add.l    d1,d1
  670.     add.l    d0,d1
  671.  
  672.     swap    d1
  673.     move.w    d1,3*DCTSIZE*2-2(a0)
  674.     swap    d0
  675.     move.w    d0,4*DCTSIZE*2-2(a0)
  676.  
  677.     sub.l    d5,d7
  678.     add.l    d5,d5
  679.     add.l    d7,d5
  680.  
  681.     swap    d5
  682.     move.w    d5,1*DCTSIZE*2-2(a0)
  683.     swap    d7
  684.     move.w    d7,6*DCTSIZE*2-2(a0)
  685.  
  686.     sub.l    d2,d3
  687.     add.l    d2,d2
  688.     add.l    d3,d2
  689.  
  690.     swap    d2
  691.     move.w    d2,2*DCTSIZE*2-2(a0)
  692.     swap    d3
  693.     move.w    d3,5*DCTSIZE*2-2(a0)
  694.  
  695. idct2_next:
  696.     move.l    (sp)+,d7
  697.     dbra    d7,idct2
  698.  
  699.     add.w    #16,sp
  700.     movem.l    (sp)+,JREVDCTREGS
  701.     rts
  702.  
  703.  
  704.     ifeq    1
  705. ; ************************************************************************************
  706.  
  707. ; Perform the inverse DCT on one block of coefficients.
  708. ;
  709. ; void j_rev_dct_sparse (DCTBLOCK data, int pos)  
  710.  
  711. ;    XDEF    @j_rev_dct_sparse
  712. @j_rev_dct_sparse:
  713.  
  714.     tst.l    d0
  715.     bne    itsnotthedc
  716.  
  717. ; the single element to cope with is the dc coefficient
  718.  
  719.     move.w    (a0),d1
  720.     bpl.s    scale_dc
  721.     subq.w    #3+4,d1                ; "implement" the rounding error
  722. scale_dc:addq.w    #4,d1
  723.     asr.w    #3,d1
  724.  
  725.     move.w    d1,d0                ; extend to longword
  726.     swap    d0
  727.     move.w    d1,d0
  728.  
  729.     moveq    #7,d1
  730. set_dc:    move.l    d0,(a0)+
  731.     move.l    d0,(a0)+
  732.     move.l    d0,(a0)+
  733.     move.l    d0,(a0)+
  734.     dbra    d1,set_dc
  735.  
  736.     rts                    ; not that pretty
  737. ;    bra    exit_jrds
  738. itsnotthedc:
  739.     movem.l    d2/d3,-(sp)
  740.  
  741. ; Some other coefficient. 
  742.  
  743.     move.w    (a0,d0.w),d1        ; get coeff
  744.  
  745.     lea    PreIDCT,a1        ; get precalculated DCT
  746.     lsl.l    #7,d0
  747.     add.l    d0,a1
  748.  
  749.     moveq    #CONST_BITS-PASS1_BITS-8,d3    ; scale down
  750.  
  751.     moveq.l    #31,d0
  752. set_ac:    move.w    d1,d2
  753.     muls    (a1)+,d2
  754.     lsr.l    d3,d2
  755.     move.w    d2,(a0)+
  756.     move.w    d1,d2
  757.     muls    (a1)+,d2
  758.     lsr.l    d3,d2
  759.     move.w    d2,(a0)+
  760.     dbra    d0,set_ac
  761.  
  762.     movem.l    (sp)+,d2/d3
  763. exit_jrds: rts
  764.  
  765. ; ************************************************************************************
  766.  
  767.     section bss,BSS
  768.  
  769. ;
  770. ; Precomputed idct value arrays
  771. ;
  772. PreIDCT: ds.w    64*64
  773.  
  774.     endc
  775.  
  776.  
  777.     END
  778.